require 'watir'
require '/Users/xz2210/Christine_Columbia/Summer_Internship_2010/shermanstravelmedia/environment/html_class_v2/classes/html.class'

site = "http://www.google.com/"

browser_type = 'Firefox'
#~ browser_type = 'Firefox'
test_environment = 'QA'

# initialize HTML report
@html = HTMLReport.new()
# createReport(reportName, header)
@report = @html.createReport('google_search', 'Google Search', browser_type)

# begin
begin
  if browser_type == 'IE'
    @browser = Watir::Browser.start(site)
  elsif browser_type == 'Firefox'
    Watir::Browser.default = 'firefox'
    @browser = Watir::Browser.start(site)
  end
  

  ######################################
  test_case = @html.newTestName('Verify controls')
  ######################################
  
  test = 'Check search text field'
  @html.add_to_report(@browser.text_field(:name, 'q').exists?, test, 'PASS: Located search text field', 'FAIL: Unable to locate search field')
  
  test = 'Check Google Search button'
  @html.add_to_report(@browser.button(:name, 'btnG').exists?, test, 'PASS: Located Google Search button', 'FAIL: Unable to locate Google Search button')
  
  test = 'Check Feeling Lucky button'
  @html.add_to_report(@browser.button(:name, 'btnI').exists?, test, 'PASS: Located Feeling Lucky button', 'FAIL: Unable to locate Feeling Lucky button')
  
  ######################################
  test_case = @html.newTestName('Perfom Watir search')
  ######################################
  
  @browser.text_field(:name, 'q').set 'Watir'
  @browser.button(:name, 'btnG').click

  test = 'Check valid search results (1)'
  @html.add_to_report(@browser.text.include?('Babysteps in WATIR'), test, 'PASS: Located text "Babysteps in WATIR"', 'FAIL: Unable to locate text "Babysteps in WATIR"')
  
  test = 'Check valid search results (2)'
  @html.add_to_report(@browser.text.include?('Project Info'), test, 'PASS: Located text "Project Info"', 'FAIL: Unable to locate text "Project Info"')
  
  test = 'Check for invalid search results'
  @html.add_to_report(@browser.text.include?('Suez Canal'), test, 'PASS: Unable to locate text "Suez Canal"', 'FAIL: Located text "Suez Canal"')
  
  # teardown
  @browser.close
  @html.finishReport(@report, browser_type, test_environment)

  rescue => e
    puts $!
    puts e.backtrace
    @html.finishReport(@report, browser_type, test_environment)
    #~ @browser.close

end
